<!DOCTYPE html>
<html>

<div th:replace="common/jsCssRef :: jsfJsCssRef"></div>

<body class="bgf6">

<div th:replace="common/head :: jsfHeader"></div>

<div class="main-body pb100">
    <div class="container pt10">
        <div class="dflx sbt">
            <div th:replace="common/left :: jsfLeft"></div>

            <div class="body-right">
                <div class="bread-nav bgff">
                    <ul class="dflx">
                        <li><a href="###">商户结算</a></li>
                    </ul>
                </div>

                    <div class="bgff mt10" id="app">
                        <div class="wrap">
                            <!--筛选条件/操作-->
                            <div class="row">
                                <div class="col-md-4">
                                    <input type="text" id="merchantName" class="form-control" placeholder="商户名称">
                                </div>
                                <div class="col-md-4">
                                    <select class="form-control c999" id="area">
                                        <option selected value="-1">全部区域</option>
                                        <option :value="area.id" v-for="area in areas">{{area.areaName}}</option>

                                    </select>
                                </div>
                                <div class="col-md-4">
                                    <select class="form-control c999" id="merStatus">
                                        <option selected value="-1">商户状态</option>
                                        <option value="0">申请中</option>
                                        <option value="1">筹备中</option>
                                        <option value="2">运营中</option>
                                        <option value="3">打烊</option>
                                        <option value="4">禁用</option>
                                    </select>
                                </div>
                                <div class="col-md-4">
                                    <br>
                                    <button type="button" id="search" class="btn btn-primary f12" @click="loadPlanList()"> 查询</button>
                                </div>
                            </div>

                            <form/>



                            <!--表格部分-->
                            <table class="table th52 f14 table-bordered mt20 table-hover" id="cityPlanTable">
                                <template>
                                    <el-table
                                            ref="multipleTable"
                                            :data="merchants"
                                            tooltip-effect="dark"
                                            style="width: 100%"
                                            @selection-change="handleSelectionChange">

                                        <el-table-column
                                                type="selection"
                                                width="55">
                                        </el-table-column>
                                        <el-table-column
                                                label="ID"
                                                width="50">
                                            <template slot-scope="scope">{{ scope.row.id }}</template>
                                        </el-table-column>
                                        <el-table-column
                                                prop="merchantName"
                                                label="商户名称"
                                                width="150">
                                        </el-table-column>
                                        <el-table-column
                                                prop="areaName"
                                                label="地点"
                                                width="120">
                                        </el-table-column>
                                        <el-table-column
                                                prop="phone"
                                                label="电话"
                                                width="120">
                                        </el-table-column>
                                        <el-table-column
                                                prop="createTime"
                                                label="创建时间"
                                                width="120">
                                        </el-table-column>
                                        <el-table-column
                                                label="当前状态"
                                                width="80">
                                            <template slot-scope="scope">{{  planStatus(scope.row.status) }}</template>
                                        </el-table-column>
                                        <el-table-column label="操作" width="160">
                                            <template slot-scope="scope">
                                                <el-button
                                                        v-if="scope.row.status == 0"
                                                        size="mini"
                                                        @click="handleShenqing(scope.$index, scope.row)">批准</el-button>

                                                <el-button
                                                        v-if="scope.row.status != 0 && scope.row.status != 4"
                                                        size="mini"
                                                        @click="handleJinyong(scope.$index, scope.row)">禁用</el-button>

                                                <el-button
                                                        v-if="scope.row.status == 4"
                                                        size="mini"
                                                        @click="handleJiejin(scope.$index, scope.row)">解除禁用</el-button>

                                                <el-link target="_blank" type="primary" :href="'/view/editArea?id=' + scope.row.id">&nbsp;&nbsp;详情</el-link>
                                                <el-link target="_blank" type="primary" :href="'/view/editArea?id=' + scope.row.id">&nbsp;&nbsp;结算</el-link>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </template>

                            </table>

                            <!--表格尾部-->
                            <div class="dflx aic sbt pb20">
                                <el-pagination
                                        @size-change="handleSizeChange"
                                        @current-change="handleCurrentChange"
                                        :current-page="currentPage"
                                        :page-sizes="[2, 50, 100]"
                                        :page-size="2"
                                        layout="total, sizes, prev, pager, next, jumper"
                                        :total="totalElement">
                                </el-pagination>
                            </div>

                        </div>
                    </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">

    $(document).ready(function () {
        $('#merchantLi').addClass('active');
    });
    
    function toAddPlan() {
        window.location.href = '/view/addArea';
    }


    var statusPlanObj = {
        '0' : '申请中',
        '1' : '筹备中',
        '2' : '营业中',
        '3' : '打烊',
        '4' : '禁用'
    }
    

    var appPage = new Vue({
        el : '#app',
        data : {
            merchants:[],
            areas : [],
            multipleSelection: [],
            currentPage : 1,
            totalElement : 1,
            pageSize : 2
        },
        created : function() {
            this.loadPlanList();
            this.loadAreas();
        },
        computed : {

        },
        methods : {
            loadAreas : function () {
                let that = this;
                $.ajax({
                    'url' : '/admin/listArea',
                    'dataType' : 'json',
                    'type' : 'get',
                    'data' : {
                        pageSize: 200,   //页面大小originUnit
                        pageNumber: 1,//页码
                        areaName: ""
                    },
                    'success' : function (result) {
                        if (result.code != 1000) {
                            alert(result.message);
                            return;
                        }

                        that.areas = result.data.data;
                    },
                    'error' : function (result) {
                    }
                });
            },
            loadPlanList : function () {
                let that = this;
                $.ajax({
                    'url' : '/admin/listMerchant',
                    'dataType' : 'json',
                    'type' : 'get',
                    'data' : {
                        pageSize: that.pageSize,   //页面大小originUnit
                        pageNumber: that.currentPage,//页码
                        merchantName: $("#merchantName").val(),
                        areaId: $("#area").val(),
                        status: $("#merStatus").val()
                    },
                    'success' : function (result) {
                        if (result.code != 1000) {
                            alert(result.message);
                            return;
                        }

                        that.merchants = result.data.data;
                        that.totalElement = result.data.totalElement;
                    },
                    'error' : function (result) {
                    }
                });
            },
            handleSelectionChange :  function (val) {
                this.multipleSelection = val;
            },

            //1-草稿 2-已提交 3-审定通过 4-审定不通过 5-批准通过 6-批准不通过
            planStatus : function (val) {
                return statusPlanObj[val];
            },

            handleSizeChange : function(val) {
                this.pageSize = val;
                this.loadPlanList();
            },

            handleCurrentChange : function(val) {
                this.currentPage = val;
                this.loadPlanList();
            },

            handleShenqing: function(index, row) {
                this.$confirm('确定通过'+row.merchantName+'的申请?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    processChange(row.id, 1);

                }).catch(() => {
                        this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });

            },

            handleJinyong : function (index, row) {
                this.$confirm('确定禁用'+row.merchantName+'商铺?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    processChange(row.id, 4);

                }).catch(() => {
                        this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });
            },
            handleJiejin : function (index, row) {
                this.$confirm('开通'+row.merchantName+'商铺?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    processChange(row.id, 1);

            }).catch(() => {
                    this.$message({
                    type: 'info',
                    message: '已取消'
                });
            });
            }

        }
    })
    
    function processChange(id, status) {
        $.ajax({
            'url' :'/admin/changeMerchant',
            'dataType' : 'json',
            'type' : 'post',
            'data' : {
                'merchantId' : id,
                'status' : status
            },
            'success' : function (result) {
                if (result.code != 1000) {
                    alert(result.message);
                    return;
                }

                window.location.reload();
            },
            'error' : function (result) {
            }
        });

    }


    $('#datepicker').fdatepicker({
        format: 'yyyy-mm-dd'
    });


</script>
</body>
</html>